import { createSlice } from "@reduxjs/toolkit";

const countStore = createSlice({
    name:'counter',
    initialState:{
        count:0
    },
    // 修改状态的方法
    reducers:{
        increment(state){
            state.count++
        },
        decrement(state){
            state.count--
        },
        addToNum(state,action){
            state.count = action.payload
        }
    }
})
// 结构出来actionCreater
const {increment, decrement,addToNum} = countStore.actions
const reducers = countStore.reducer

export {increment, decrement,addToNum}
export default reducers